<%@ Page Language="C#" MasterPageFile="AdminMasterPage.master" AutoEventWireup="true" CodeFile="BlogAdmin.aspx.cs" Inherits="Admin_BlogAdmin" Title="Untitled Page" ValidateRequest="false" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">

          <br />
          <h2>Blog Content</h2><br /><asp:SqlDataSource id="SqlDataSource2" runat="server" SelectCommand="SELECT * FROM [Blog]order by PostDate desc" UpdateCommand="UPDATE [Blog] SET [PostTitle] = @PostTitle, [PostContent] = @PostContent, [PostDate] = @PostDate, [PostedBy] = @PostedBy, [PostCaption] = @PostCaption,[PostTags]=@PostTags WHERE [BlogID] = @BlogID" InsertCommand="INSERT INTO [Blog] ([PostTitle], [PostContent], [PostDate], [PostedBy], [PostCaption],[PostTags]) VALUES (@PostTitle, @PostContent, @PostDate, @PostedBy, @PostCaption, @postTags)" ConnectionString="<%$ ConnectionStrings:Personal %>" DeleteCommand="DELETE FROM [Blog] WHERE [BlogID] = @BlogID"><DeleteParameters>
<asp:Parameter Type="Int32" Name="BlogID"></asp:Parameter>
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Type="String" Name="PostTitle"></asp:Parameter>
<asp:Parameter Type="String" Name="PostContent"></asp:Parameter>
<asp:Parameter Type="DateTime" Name="PostDate"></asp:Parameter>
<asp:Parameter Type="String" Name="PostedBy"></asp:Parameter>
<asp:Parameter Type="String" Name="PostCaption"></asp:Parameter>
<asp:Parameter Type="Int32" Name="BlogID"></asp:Parameter>
</UpdateParameters>
<InsertParameters>
<asp:Parameter Type="String" Name="PostTitle"></asp:Parameter>
<asp:Parameter Type="String" Name="PostContent"></asp:Parameter>
<asp:Parameter Type="DateTime" Name="PostDate"></asp:Parameter>
<asp:Parameter Type="String" Name="PostedBy"></asp:Parameter>
<asp:Parameter Type="String" Name="PostCaption"></asp:Parameter>
</InsertParameters>
</asp:SqlDataSource> <asp:DetailsView id="DetailsView1" runat="server" DataSourceID="SqlDataSource2" DataKeyNames="BlogID" AllowPaging="True" Height="97px" Width="638px" AutoGenerateRows="False" OnItemInserted="DetailsView1_ItemInserted" OnItemUpdated="DetailsView1_ItemUpdated" OnItemInserting="DetailsView1_ItemInserting" OnItemUpdating="DetailsView1_ItemUpdating">
                        <PagerSettings Mode="NumericFirstLast" />
                        <Fields>
<asp:TemplateField SortExpression="BlogID" HeaderText="BlogID" InsertVisible="False"><EditItemTemplate>
<asp:Label runat="server" Text='<%# Eval("BlogID") %>' id="Label1"></asp:Label>
</EditItemTemplate>
<ItemTemplate>
<asp:Label id="Label1" runat="server" Text='<%# Bind("BlogID") %>'></asp:Label> 
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField SortExpression="PostTitle" HeaderText="PostTitle"><EditItemTemplate>
<asp:TextBox runat="server" Text='<%# Bind("PostTitle") %>' id="TextBox1"></asp:TextBox>
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox runat="server" Text='<%# Bind("PostTitle") %>' id="TextBox1"></asp:TextBox>
</InsertItemTemplate>
<ItemTemplate>
<asp:Label runat="server" Text='<%# Bind("PostTitle") %>' id="Label2"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField SortExpression="PostContent" HeaderText="PostContent"><EditItemTemplate>
<asp:TextBox id="TextBox2" runat="server" Text='<%# Bind("PostContent") %>' Height="109px" Width="608px" TextMode="MultiLine"></asp:TextBox> 
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox id="TextBox2" runat="server" Text='<%# Bind("PostContent") %>' Height="121px" Width="604px" TextMode="MultiLine"></asp:TextBox> 
</InsertItemTemplate>
<ItemTemplate>
<asp:Label id="Label3" runat="server" Text='<%# Bind("PostContent") %>'></asp:Label> 
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="PostDate" SortExpression="PostDate" HeaderText="PostDate"></asp:BoundField>
<asp:BoundField DataField="PostedBy" SortExpression="PostedBy" HeaderText="PostedBy"></asp:BoundField>
<asp:TemplateField SortExpression="PostCaption" HeaderText="PostCaption"><EditItemTemplate>
<asp:TextBox runat="server" Text='<%# Bind("PostCaption") %>' id="TextBox3"></asp:TextBox>
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox runat="server" Text='<%# Bind("PostCaption") %>' id="TextBox3"></asp:TextBox>
</InsertItemTemplate>
<ItemTemplate>
<asp:Label runat="server" Text='<%# Bind("PostCaption") %>' id="Label4"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
    <asp:TemplateField HeaderText="PostTags" SortExpression="PostTags">
        <EditItemTemplate>
            <asp:TextBox ID="TextBox4" runat="server" Text='<%# Bind("PostTags") %>'></asp:TextBox>
            &nbsp;
        </EditItemTemplate>
        <InsertItemTemplate>
            <asp:TextBox ID="TextBox4" runat="server" Text='<%# Bind("PostTags") %>'></asp:TextBox>
            &nbsp;
        </InsertItemTemplate>
        <ItemTemplate>
            <asp:Label ID="Label5" runat="server" Text='<%# Bind("PostTags") %>'></asp:Label>
        </ItemTemplate>
    </asp:TemplateField>
<asp:CommandField ShowInsertButton="True" ShowEditButton="True"></asp:CommandField>
</Fields>
</asp:DetailsView>
          <br />
         <br />
         <h2>Blog Comments</h2>
          <br /><asp:DetailsView id="DetailsView2" runat="server" DataSourceID="SqlDataSource3" DataKeyNames="CommentID" AllowPaging="True" Height="50px" Width="643px" AutoGenerateRows="False"><Fields>
              <asp:BoundField DataField="CommentID" HeaderText="CommentID" InsertVisible="False"
                  ReadOnly="True" SortExpression="CommentID" />
              <asp:BoundField DataField="PostTitle" HeaderText="PostTitle" ReadOnly="True" SortExpression="PostTitle" />
              <asp:BoundField DataField="CommentBy" HeaderText="CommentBy" SortExpression="CommentBy" />
              <asp:BoundField DataField="CommentDesc" HeaderText="CommentDesc" SortExpression="CommentDesc" />
              <asp:BoundField DataField="IPAddress" HeaderText="IPAddress" SortExpression="IPAddress" />
              <asp:BoundField DataField="BlogID" HeaderText="BlogID" SortExpression="BlogID" />
              <asp:CheckBoxField DataField="IsPublished" HeaderText="IsPublished" SortExpression="IsPublished" />
              <asp:BoundField DataField="CommentDate" HeaderText="CommentDate" SortExpression="CommentDate" />
              <asp:BoundField DataField="Email" HeaderText="Email" SortExpression="Email" />
</Fields>
</asp:DetailsView><br /><br /><br /><asp:SqlDataSource id="SqlDataSource1" runat="server" SelectCommand="SELECT * FROM [Blog] ORDER BY [PostDate] DESC, [PostTitle]" UpdateCommand="UPDATE [Blog] SET [PostTitle] = @PostTitle, [PostContent] = @PostContent, [PostDate] = @PostDate, [PostedBy] = @PostedBy, [PostCaption] = @PostCaption WHERE [BlogID] = @BlogID" InsertCommand="INSERT INTO [Blog] ([PostTitle], [PostContent], [PostDate], [PostedBy], [PostCaption]) VALUES (@PostTitle, @PostContent, @PostDate, @PostedBy, @PostCaption)" ConnectionString="<%$ ConnectionStrings:Personal %>" DeleteCommand="DELETE FROM [Blog] WHERE [BlogID] = @BlogID"><DeleteParameters>
<asp:Parameter Type="Int32" Name="BlogID"></asp:Parameter>
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Type="String" Name="PostTitle"></asp:Parameter>
<asp:Parameter Type="String" Name="PostContent"></asp:Parameter>
<asp:Parameter Type="DateTime" Name="PostDate"></asp:Parameter>
<asp:Parameter Type="String" Name="PostedBy"></asp:Parameter>
<asp:Parameter Type="String" Name="PostCaption"></asp:Parameter>
<asp:Parameter Type="Int32" Name="BlogID"></asp:Parameter>
</UpdateParameters>
<InsertParameters>
<asp:Parameter Type="String" Name="PostTitle"></asp:Parameter>
<asp:Parameter Type="String" Name="PostContent"></asp:Parameter>
<asp:Parameter Type="DateTime" Name="PostDate"></asp:Parameter>
<asp:Parameter Type="String" Name="PostedBy"></asp:Parameter>
<asp:Parameter Type="String" Name="PostCaption"></asp:Parameter>
</InsertParameters>
</asp:SqlDataSource> 

 <h2>Blog Content Table</h2>
<asp:GridView id="GridView2" runat="server" DataSourceID="SqlDataSource1" DataKeyNames="BlogID" AutoGenerateColumns="False" AllowPaging="True" AllowSorting="True"><Columns>
    <asp:CommandField ShowDeleteButton="True" />
    <asp:BoundField DataField="BlogID" HeaderText="BlogID" InsertVisible="False" ReadOnly="True"
        SortExpression="BlogID" />
    <asp:BoundField DataField="PostTitle" HeaderText="PostTitle" SortExpression="PostTitle" />
    <asp:BoundField DataField="PostDate" HeaderText="PostDate" SortExpression="PostDate" />
    <asp:BoundField DataField="PostedBy" HeaderText="PostedBy" SortExpression="PostedBy" />
    <asp:BoundField DataField="PostCaption" HeaderText="PostCaption" SortExpression="PostCaption" />
</Columns>
</asp:GridView><br /><asp:SqlDataSource id="SqlDataSource3" runat="server" SelectCommand="SELECT  CommentID, (SELECT PostTitle FROM Blog WHERE (BlogID = BlogComment.BlogID)) AS PostTitle, CommentBy, CommentDesc, IPAddress, BlogID, IsPublished, CommentDate, Email FROM BlogComment" UpdateCommand="UPDATE [BlogComment] SET [CommentBy] = @CommentBy, [CommentDesc] = @CommentDesc, [IPAddress] = @IPAddress, [BlogID] = @BlogID, [IsPublished] = @IsPublished, [CommentDate] = @CommentDate, [Email] = @Email WHERE [CommentID] = @CommentID" InsertCommand="INSERT INTO [BlogComment] ([CommentBy], [CommentDesc], [IPAddress], [BlogID], [IsPublished], [CommentDate], [Email]) VALUES (@CommentBy, @CommentDesc, @IPAddress, @BlogID, @IsPublished, @CommentDate, @Email)" ConnectionString="<%$ ConnectionStrings:Personal %>" DeleteCommand="DELETE FROM [BlogComment] WHERE [CommentID] = @CommentID"><DeleteParameters>
                    <asp:Parameter Type="Int32" Name="CommentID"></asp:Parameter>
                    </DeleteParameters>
                <UpdateParameters>
                <asp:Parameter Type="String" Name="CommentBy"></asp:Parameter>
                <asp:Parameter Type="String" Name="CommentDesc"></asp:Parameter>
                <asp:Parameter Type="String" Name="IPAddress"></asp:Parameter>
                <asp:Parameter Type="Int32" Name="BlogID"></asp:Parameter>
                <asp:Parameter Type="Boolean" Name="IsPublished"></asp:Parameter>
                <asp:Parameter Type="DateTime" Name="CommentDate"></asp:Parameter>
                <asp:Parameter Type="String" Name="Email"></asp:Parameter>
                <asp:Parameter Type="Int32" Name="CommentID"></asp:Parameter>
                </UpdateParameters>
                <InsertParameters>
                <asp:Parameter Type="String" Name="CommentBy"></asp:Parameter>
                <asp:Parameter Type="String" Name="CommentDesc"></asp:Parameter>
                <asp:Parameter Type="String" Name="IPAddress"></asp:Parameter>
                <asp:Parameter Type="Int32" Name="BlogID"></asp:Parameter>
                <asp:Parameter Type="Boolean" Name="IsPublished"></asp:Parameter>
                <asp:Parameter Type="DateTime" Name="CommentDate"></asp:Parameter>
                <asp:Parameter Type="String" Name="Email"></asp:Parameter>
                </InsertParameters>
                </asp:SqlDataSource>
                <h2>Blog Comment Table</h2>
                <asp:GridView id="GridView1" runat="server" DataSourceID="SqlDataSource3" DataKeyNames="CommentID" AllowSorting="True" AutoGenerateColumns="False" AllowPaging="True" OnSelectedIndexChanging="GridView1_SelectedIndexChanging"><Columns>
                    <asp:BoundField DataField="CommentID" HeaderText="CommentID" InsertVisible="False"
                        ReadOnly="True" SortExpression="CommentID" />
                    <asp:BoundField DataField="PostTitle" HeaderText="PostTitle" ReadOnly="True" SortExpression="PostTitle" />
                    <asp:BoundField DataField="CommentBy" HeaderText="CommentBy" SortExpression="CommentBy" />
                    <asp:BoundField DataField="CommentDesc" HeaderText="CommentDesc" SortExpression="CommentDesc" />
                    <asp:BoundField DataField="IPAddress" HeaderText="IPAddress" SortExpression="IPAddress" />
                    <asp:BoundField DataField="BlogID" HeaderText="BlogID" SortExpression="BlogID" />
                    <asp:CheckBoxField DataField="IsPublished" HeaderText="IsPublished" SortExpression="IsPublished" />
                    <asp:BoundField DataField="CommentDate" HeaderText="CommentDate" SortExpression="CommentDate" />
                    <asp:BoundField DataField="Email" HeaderText="Email" SortExpression="Email" />
</Columns>
</asp:GridView> 
        <br />
        <br />
        <h2>Tag Table</h2>
          <asp:GridView ID="GridView3" runat="server" AllowPaging="True" 
              AllowSorting="True" AutoGenerateColumns="False" DataKeyNames="TagId" 
              DataSourceID="SqlDataSource4">
              <Columns>
                  <asp:CommandField ShowDeleteButton="True" ShowEditButton="True" />
                  <asp:BoundField DataField="TagId" HeaderText="TagId" InsertVisible="False" 
                      ReadOnly="True" SortExpression="TagId" />
                  <asp:BoundField DataField="TagName" HeaderText="TagName" 
                      SortExpression="TagName" />
                  <asp:BoundField DataField="TagCount" HeaderText="TagCount" 
                      SortExpression="TagCount" />
              </Columns>
            </asp:GridView>
          <asp:SqlDataSource ID="SqlDataSource4" runat="server" 
              ConnectionString="<%$ ConnectionStrings:Personal %>" 
              DeleteCommand="DELETE FROM [BlogTag] WHERE [TagId] = @TagId" 
              InsertCommand="INSERT INTO [BlogTag] ([TagName], [TagCount]) VALUES (@TagName, @TagCount)" 
              SelectCommand="SELECT * FROM [BlogTag]" 
              UpdateCommand="UPDATE [BlogTag] SET [TagName] = @TagName, [TagCount] = @TagCount WHERE [TagId] = @TagId">
              <DeleteParameters>
                  <asp:Parameter Name="TagId" Type="Int32" />
              </DeleteParameters>
              <UpdateParameters>
                  <asp:Parameter Name="TagName" Type="String" />
                  <asp:Parameter Name="TagCount" Type="Int32" />
                  <asp:Parameter Name="TagId" Type="Int32" />
              </UpdateParameters>
              <InsertParameters>
                  <asp:Parameter Name="TagName" Type="String" />
                  <asp:Parameter Name="TagCount" Type="Int32" />
              </InsertParameters>
          </asp:SqlDataSource>
          <br /><br />
          <h2>Tag Detail</h2>
    <asp:DetailsView ID="DetailsView3" runat="server" Height="50px" Width="125px" 
              AllowPaging="True" AutoGenerateRows="False" DataKeyNames="TagId" 
              DataSourceID="SqlDataSource4">
        <Fields>
            <asp:BoundField DataField="TagId" HeaderText="TagId" InsertVisible="False" 
                ReadOnly="True" SortExpression="TagId" />
            <asp:BoundField DataField="TagName" HeaderText="TagName" 
                SortExpression="TagName" />
            <asp:BoundField DataField="TagCount" HeaderText="TagCount" 
                SortExpression="TagCount" />
            <asp:CommandField ShowDeleteButton="True" ShowEditButton="True" 
                ShowInsertButton="True" />
        </Fields>
    </asp:DetailsView>
</asp:Content>

